<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>动态组件和v-once指令的使用</title>
    <script src="js/vue.js"></script>
</head>
<body>
    <div id="root">

<!--        <child-one v-if="type==='child-one'"></child-one>-->
<!--        <child-two v-if="type==='child-two'"></child-two>-->
        <keep-alive><component :is="type"></component></keep-alive>
        <button @click="handleBtnClick">change</button>
    </div>
    <script>
        Vue.component("child-one", {
            template: "<div v-once>child-one</div>"
        });
        Vue.component("child-two", {
            template: "<div v-once>child-two</div>"
        });
        var vm = new Vue({
            el: "#root",
            data: {
                type: 'child-one'
            },
            methods: {
                handleBtnClick: function () {
                    this.type = this.type ==="child-one" ? "child-two" : "child-one"
                }
            }
        })
    </script>
</body>
</html>